kernel void sortEvenColumns(global float4 *positions,
							global float2 *originalID,
							int agents_mesh_width){
							
	unsigned int x = 2 * get_global_id(0);
	unsigned int y = get_global_id(1);
	
	if(x > agents_mesh_width-2)
		return;
	
	float4 myPos = positions[y * agents_mesh_width + x];
	float4 neighborPos = positions[y * agents_mesh_width + (x+1)];
	
	if(myPos.x > neighborPos.x){
		float2 myID = originalID[y * agents_mesh_width + x];
		float2 neighborID = originalID[y * agents_mesh_width + (x+1)];
		
		positions[y * agents_mesh_width + x] = neighborPos;
		positions[y * agents_mesh_width + (x+1)] = myPos;
		
		originalID[y * agents_mesh_width + x] = neighborID;
		originalID[y * agents_mesh_width + (x+1)] = myID;
	}
}

kernel void sortOddColumns(global float4 *positions,
							global float2 *originalID,
							int agents_mesh_width){
							
	unsigned int x = 2*get_global_id(0) + 1;
	unsigned int y = get_global_id(1);
	
	if(x > agents_mesh_width-3)
		return;
	
	float4 myPos = positions[y * agents_mesh_width + x];
	float4 neighborPos = positions[y * agents_mesh_width + (x+1)];
	
	if(myPos.x > neighborPos.x){
		float2 myID = originalID[y * agents_mesh_width + x];
		float2 neighborID = originalID[y * agents_mesh_width + (x+1)];
		
		positions[y * agents_mesh_width + x] = neighborPos;
		positions[y * agents_mesh_width + (x+1)] = myPos;
		
		originalID[y * agents_mesh_width + x] = neighborID;
		originalID[y * agents_mesh_width + (x+1)] = myID;
	}
}

kernel void sortEvenRows(global float4 *positions,
							global float2 *originalID,
							int agents_mesh_width){
							
	unsigned int x = get_global_id(0);
	unsigned int y = 2*get_global_id(1);
	
	if(y > agents_mesh_width-2)
		return;
	
	float4 myPos = positions[y * agents_mesh_width + x];
	float4 neighborPos = positions[(y+1) * agents_mesh_width + x];
	
	if(myPos.y > neighborPos.y){
		float2 myID = originalID[y * agents_mesh_width + x];
		float2 neighborID = originalID[(y+1) * agents_mesh_width + x];
		
		positions[y * agents_mesh_width + x] = neighborPos;
		positions[(y+1) * agents_mesh_width + x] = myPos;
		
		originalID[y * agents_mesh_width + x] = neighborID;
		originalID[(y+1) * agents_mesh_width + x] = myID;
	}
}

kernel void sortOddRows(global float4 *positions,
							global float2 *originalID,
							int agents_mesh_width){
							
	unsigned int x = get_global_id(0);
	unsigned int y = 2*get_global_id(1) + 1;
	
	if(y > agents_mesh_width-3)
		return;
	
	float4 myPos = positions[y * agents_mesh_width + x];
	float4 neighborPos = positions[(y+1) * agents_mesh_width + x];
	
	if(myPos.y > neighborPos.y){
		float2 myID = originalID[y * agents_mesh_width + x];
		float2 neighborID = originalID[(y+1) * agents_mesh_width + x];
		
		positions[y * agents_mesh_width + x] = neighborPos;
		positions[(y+1) * agents_mesh_width + x] = myPos;
		
		originalID[y * agents_mesh_width + x] = neighborID;
		originalID[(y+1) * agents_mesh_width + x] = myID;
	}
}